﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LibraryMusicStore;

namespace AppMusicStore
{
    public partial class frmPreview : DevExpress.XtraEditors.XtraForm
    {
        public int Count { get; set; }
        public int Sum { get; set; }
        public DataTable dt { get; set; }
        public string String1 { get; set; }
        public string String2 { get; set; }

        rptQuantitySold rpt;
        rptStock rptStock;

        public frmPreview()
        {
            InitializeComponent();
        }

        private void frmPreview_Load(object sender, EventArgs e)
        {
            if (Count == 0) Init();
            else Init2();
        }

        private void Init()
        {
            try
            {
                rptStock = new rptStock();
                rptStock.String1 = String1;
                rptStock.String2 = String2;
                rptStock.BindData();

                printControl1.PrintingSystem = rptStock.PrintingSystem;
                //rpt.LoadLayout(Application.StartupPath + "\\rptStock1.repx");
                rptStock.CreateDocument();
            }
            catch (Exception)
            {
                Close();
                throw;
            }
        }

        private void Init2()
        {
            try
            {
                rpt = new rptQuantitySold();
                rpt.Count = Count;
                rpt.Sum = Sum;
                rpt.String1 = String1;
                rpt.String2 = String2;
                rpt.DataSource = dt;
                rpt.BindData();

                printControl1.PrintingSystem = rpt.PrintingSystem;
                //rpt.LoadLayout(Application.StartupPath + "\\rptStock1.repx");
                rpt.CreateDocument();
            }
            catch (Exception)
            {
                Close();
                throw;
            }
        }

        private void EditBarButtonItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (Count == 0)
            {
                rptStock.ShowDesignerDialog();
                rptStock.CreateDocument();
            }
            else
            {
                // Show the End-User Designer form, modally. 
                rpt.ShowDesignerDialog();

                // Re-generate the report's print document. 
                rpt.CreateDocument();
            }
        }
    }
}